package com.crx.springbootinit.controller.user;

import com.crx.springbootinit.annotation.LogApiAnno;
import com.crx.springbootinit.common.BaseResponse;
import com.crx.springbootinit.common.ResultUtils;
import com.crx.springbootinit.model.dto.collect.CollectPageDTO;
import com.crx.springbootinit.model.dto.love.LoveAndCollectPageDTO;
import com.crx.springbootinit.model.dto.love.LoveGiveDTO;
import com.crx.springbootinit.model.dto.love.LovePageDTO;
import com.crx.springbootinit.model.dto.page.PageQuery;
import com.crx.springbootinit.model.dto.page.PageVO;
import com.crx.springbootinit.model.vo.collect.CollectMyPostVO;
import com.crx.springbootinit.model.vo.love.LoveAndCollectMeVO;
import com.crx.springbootinit.model.vo.love.LoveMyPostVO;
import com.crx.springbootinit.model.vo.love.LovePostListVO;
import com.crx.springbootinit.service.ILoveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 点赞表 前端控制器
 * </p>
 *
 * @author 谢杭延
 * @since 2024-10-21
 */
@RestController
@RequestMapping("/user/love")
@RequiredArgsConstructor
@Api(tags = "点赞模块接口")
public class LoveController {

    private final ILoveService loveService;

    @PostMapping
    @ApiOperation("点赞和取消点赞")
    @LogApiAnno(title = "点赞模块", businessType = "POST")
    public BaseResponse<Void> giveLove(@RequestBody LoveGiveDTO loveGiveDTO){
        loveService.giveLove(loveGiveDTO);
        return ResultUtils.success();
    }

    @GetMapping("me")
    @ApiOperation("查询点赞我帖子的人列表")
    @LogApiAnno(title = "点赞模块", businessType = "GET")
    public BaseResponse<List<LoveMyPostVO>> queryWhoLoveMyPostList(@RequestHeader String token){
        List<LoveMyPostVO> list = loveService.queryWhoLoveMyPostList(token);
        return ResultUtils.success(list);
    }

    @GetMapping("list")
    @ApiOperation("查询我点赞的帖子列表")
    @LogApiAnno(title = "点赞模块", businessType = "GET")
    public BaseResponse<List<LovePostListVO>> queryMyLoveList(@RequestHeader String token){
        List<LovePostListVO> list = loveService.queryMyLovePostList(token);
        return ResultUtils.success(list);
    }

    @GetMapping("count")
    @ApiOperation("查询我的获赞数量")
    @LogApiAnno(title = "点赞模块", businessType = "GET")
    public BaseResponse<Long> getLoveMyCount(@RequestHeader String token){
        Long count = loveService.getLoveMyCount(token);
        return ResultUtils.success(count);
    }

    @GetMapping("loveAndCollectCount")
    @ApiOperation("查询我点赞和收藏的帖子数量")
    @LogApiAnno(title = "点赞模块", businessType = "GET")
    public BaseResponse<Long> getLoveAndCollectCont(@RequestHeader String token){
        Long count = loveService.getLoveAndCollectCont(token);
        return ResultUtils.success(count);
    }

    @GetMapping("loveAndCollectMe")
    @ApiOperation("分页查询点赞和收藏我的人列表")
    @LogApiAnno(title = "点赞模块", businessType = "GET")
    public BaseResponse<PageVO<LoveAndCollectMeVO>> queryLoveAndCollectMe(PageQuery pageQuery){
        PageVO<LoveAndCollectMeVO> page = loveService.queryLoveAndCollectMe(pageQuery);
        return ResultUtils.success(page);
    }

}
